import pdfkit
import pandas
data = pandas.read_csv('D://pengpai/news.csv',usecols=['title','url'])
for i in range(len(data)):
    newstitle = data['title'][i]
    newsurl = data['url'][i]
    #进行不合法字符额处理
    str = newstitle.replace('|', '')

    file_name = str

    try:
        pdfkit.from_url(newsurl,'D://pengpai/文档/'+file_name+'.pdf')
        print('已下载')
    except Exception as err:
        print(err)
